# model

# determine the following things:
#   current user
#   chosen storage-service (Amazon-S3, GoogleStorage, OpenStack ObjectStorage, aso.)
#   amount of entries in the storage
#   aso.

from google.appengine.ext import webapp

from Utilities import *
from controller.BuildRegion import *
from model.octopus.login.MainPage import *


class SetRegions(webapp.RequestHandler):
    def get(self):
        utilities = Utilities()
        
        username = utilities.getUsername()
        userText = utilities.getUserText()
        
        # check it there is an user logged-in
        if username:
            urlText = utilities.getUrlTextLogout()
            url = utilities.getLogout(self)
            hintText = ''
            hintColor = 'black'
            
            # check for credentials
            credentials = utilities.getCredentials(username)
            results = credentials.fetch(100)
            
            if not results:
#                hintText = _('Please enter your Credentials!')
                hintText = 'Please enter your Credentials!'
                hintColor = 'red'
            else:
                hintText = ''
                hintColor = 'black'
        else:
            self.redirect('/')
            urlText = utilities.getUrlTextLogin()
            url = utilities.getLogin(self)
            hintText = utilities.getHintTextFirstLogin()
            hintColor = 'red'
            
        
        # check if there are already existing credentials for this user
        credentials = utilities.getCredentials(username)       

        # templateValus contains the parameter, which are necessary for the template
        templateValues = {
                          'user': username,
                          'userText': userText,
                          'urlText': urlText,
                          'url': url,
                          'hintText': hintText, 
                          'hintColor': hintColor
                          }
        
        builder = BuildRegion()
        builder.get(self, templateValues, credentials)
        
        